<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>购物车页面</title>
	<link rel="stylesheet" href="{:config('home_static')}/style/base.css" type="text/css">
	<link rel="stylesheet" href="{:config('home_static')}/style/global.css" type="text/css">
	<link rel="stylesheet" href="{:config('home_static')}/style/header.css" type="text/css">
	<link rel="stylesheet" href="{:config('home_static')}/style/cart.css" type="text/css">
	<link rel="stylesheet" href="{:config('home_static')}/style/footer.css" type="text/css">

	<script type="text/javascript" src="{:config('home_static')}/js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="/plugin/layer/layer.js"></script>
	<script type="text/javascript" src="{:config('home_static')}/js/cart1.js"></script>
	
</head>
<body>
<!-- 顶部导航 start -->
{include file="public/nav" /}
<!-- 顶部导航 end -->
	
	<div style="clear:both;"></div>
	
	<!-- 页面头部 start -->
	<div class="header w990 bc mt15">
		<div class="logo w990">
			<h2 class="fl"><a href="{:url('home/index/index')}"><img src="{:config('home_static')}/images/logo.png" alt="京西商城"></a></h2>
			<div class="flow fr">
				<ul>
					<li class="cur">1.我的购物车</li>
					<li>2.填写核对订单信息</li>
					<li>3.成功提交订单</li>
				</ul>
			</div>
		</div>
	</div>
	<!-- 页面头部 end -->
	
	<div style="clear:both;"></div>

	<!-- 主体部分 start -->
	<div class="mycart w990 mt10 bc">
		<h2><span>我的购物车</span></h2>
		<table>
			<thead>
				<tr>
					<th class="col1">商品名称</th>
					<th class="col2">商品信息</th>
					<th class="col3">单价</th>
					<th class="col4">数量</th>	
					<th class="col5">小计</th>
					<th class="col6">操作</th>
				</tr>
			</thead>
			<tbody>
            <?php $total_price = 0; foreach($cartData as $data):?>
				<tr>
					<td class="col1"><a href="{:url('home/goods/detail',['goods_id'=>$data['goods_id']])}"><img src="/upload/{:json_decode($data['goodsInfo']['goods_middle'])[0]}" alt="" /></a> <strong><a href="">{$data['goodsInfo']['goods_name']}</a></strong></td>
					<td class="col2"> <p>{$data['attrInfo']['singleAttr']}</p></td>
					<?php $danjia = $data['goodsInfo']['goods_price'] + $data['attrInfo']['attr_total_price']?>
					<td class="col3">￥<span>{$danjia}</span></td>
					<td class="col4" goods_id="{$data['goods_id']}" goods_attr_ids="{$data['goods_attr_ids']}">
						<a href="javascript:;" class="reduce_num"></a>
                        <!-- 商品数量 -->
						<input type="text" name="amount" value="{$data['goods_number']}" class="amount"/>
						<a href="javascript:;" class="add_num"></a>
					</td>
                    <?php
                    $danjiaTotal = $danjia*$data['goods_number'];
                    $total_price += $danjiaTotal;
                    ?>
					<td class="col5">￥<span>{$danjiaTotal}</span></td>
					<td class="col6"><a class="delCartGoods" href="javascript:;" goods_attr_ids="{$data['goods_attr_ids']}" goods_id="{$data['goods_id']}">删除</a></td>
				</tr>
            <?php endforeach;?>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="6">购物金额总计： <strong>￥ <span id="total">{$total_price}</span></strong></td>
				</tr>
			</tfoot>
		</table>
		<div class="cart_btn w990 bc mt10">
			<a href="" class="continue">继续购物</a>
			<a href="javascript:;" style="margin-left: 20px;" id="clearCart" class="continue">清空购物车</a>
			<a href="{:url('home/order/orderinfo')}" class="checkout">结 算</a>
		</div>
	</div>
	<!-- 主体部分 end -->

	<div style="clear:both;"></div>
    <!-- 底部版权 start -->
    {include file="public/foot" /}
    <!-- 底部版权 end -->
</body>
<script type="text/javascript">
    //ajax删除购物车
    $(".delCartGoods").click(function()
    {
        var _self = $(this);
        //获取商品id以及商品属性id
        var goods_id = _self.attr('goods_id');
        var goods_attr_ids = _self.attr('goods_attr_ids');
        //ajax请求代码
        $.get("{:url('home/cart/ajaxDelCartGoods')}",{"goods_id":goods_id,"goods_attr_ids":goods_attr_ids},
        function(json){
            if(json.code == 200){
                //提示删除成功 并remove此行
                _self.parent().parent().remove();
                layer.msg(json.message,{"icon":1,"time":1500});
            }else{
                layer.msg(json.message,{"icon":0,"time":1500});
            }
        }
        ,'json');
    });
    //实现ajax清空购物车
    $("#clearCart").click(function () {
        $.get("{:url('home/cart/ajaxClearCartGoods')}","",function(json){
            if(json.code == 200){
                layer.msg(json.message,{"icon":"1","time":1500});
                $("tbody").html('<p style="text-align: center;">购物车空空如也，去<a href="/">首页</a>看看吧</p>');
            }else{
                layer.msg(json.message,{"icon":"0","time":1500});
            }
        },'json');
    });
</script>
</html>
